﻿''' <summary>
''' Provides extension methods to the <see cref="DataSet">DataSet</see> object.
''' </summary>
''' <revisions>
'''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
''' </revisions>
Public Module DataSetExtensions

  ''' <summary>
  ''' Determines whether the <see cref="DataSet">DataSet</see> has data.
  ''' </summary>
  ''' <param name="value">The <see cref="DataSet">DataSet</see> to test.</param>
  ''' <returns><c>true</c> if the the dataset has data; otherwise, <c>false</c>.</returns>
  ''' <remarks>Checks to see if the dataset is not Null (Nothing in Visual Basic) and has at least one table which has at least one row.</remarks>
  ''' <example>
  '''   <para>The following examples get a dataset from the Person object and then display a message box if the returned dataset has data.</para>
  '''   <code language="vb">
  '''     Public Sub ShowDisplayName(ByVal PrsnId As Integer)
  '''       Dim dsRetrivedData = Person.GetDataSet(27744)
  '''       If dsRetrievedData.HasData = True
  '''         MsgBox(dsRetrievedData.Tables(0).Rows(0).Item("DisplayName"))
  '''       End If
  '''     End Sub
  '''   </code>
  '''   <code language="c#">
  '''     public void ShowDisplayName(int PrsnId)
  '''     {
  '''     	object dsRetrivedData = Person.GetDataSet(27744);
  '''     	if (dsRetrievedData.HasData == true)
  '''     	{
  '''     		MsgBox(dsRetrievedData.Tables(0).Rows(0).Item("DisplayName"));
  '''     	}
  '''     }
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/2/2008" author="Chad Green" version="1.00.00.000">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function HasData(ByVal value As DataSet) As Boolean
    Try
      If IsNothing(value) = False AndAlso value.Tables.Count > 0 AndAlso value.Tables(0).Rows.Count > 0 Then
        Return True
      Else
        Return False
      End If
    Catch ex As Exception
      Return False
    End Try
  End Function

End Module